<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>文件管理器</title>
<link type="text/css" rel="stylesheet" href="main.css"/>
<script src="jquery.js" language="javascript" type="text/javascript"></script>
<script src="base.js" language="javascript" type="text/javascript"></script>
<script language="javascript" src="../include/dedeajax2.js"></script>
<script language='javascript' src='js/main.js'></script>
<style>
.linerow{border-bottom: 1px solid #CBD8AC;height:24px}
</style>
<script>
    $(document).ready(function(){
        $(".np").click(function(){
            ajax('achieve');
        });
        $("#go").click(function(){
            upload();
        });
        $("#typeid").change(function(){
            getChannel('1');
        });
        
        function getChannel(type){
            var type;
            var typeid = $('#typeid').val();
            $.ajax({
                type: 'GET',
                url: 'batch_action.php',
                data: {action:"getChannelID",typeid:typeid,type:type},
                success:  function(data){
//                    alert(data);
                    if(type==1){
                        if(data != 0){
                        $("#product").html(data);
                        }else{
                            $("#product").html('');
                        }
                    }else if(type == 2){
                        return data;
                    }
                    
                },
                dataType: 'html'
            });
        }
        
        function ajax(type){

            var type;
            
            var path = $('#path').val();
            var typeid = $('#typeid').val();

            
            var format = $("input[@type=radio][@checked]").val();
            if(typeid == 0){
                alert('选择分类');
            }
    //            alert(format);
    
                $.ajax({
                      type: 'GET',
                      url: 'batch_action.php',
                      data: {action:type,path:path,format:format,typeid:typeid},
                      success:  function(data){
                          if(type=='achieve'){
                              var jsonData=eval(data);
//                              alert(data);
                              var value = JSON.stringify(data);
                                var strs2 = value.split(","); 
                                var countStr2 = strs2.length;
                                $("#count").attr("value",countStr2);

                              var htmlCode=''
                              if(data != null){
                                  $.each(jsonData,  function(i, n){
        //                          alert("Data Loaded: " + n);
                                    htmlCode += '<li>'+n+'</li>';
                                  });
                              }else{
                                  htmlCode = '此目录没有'+format+'文件';
                              }
                          } 
                          
                          $("#show").html(htmlCode);
                      },
                      dataType: 'json'
                }); 
        }
        
        function upload(){
        var format = $("input[@type=radio][@checked]").val();
        var typeid = $('#typeid').val();
        //alert(typeid);
        var path = $('#path').val();
        var ishtml = $('#ishtml').val();
        var count = Number($('#count').val());
        var htmlCode=''
        var copyInContent = $('#copyInContent').val();
        var articleName = $('#articleName').val();
        var code11 ="";
        var code22 ="";
        var code33 ="";
        var code44="";
        var code55='';
        $.each($("#product :input"),  function(i, n){
            code11 = jQuery(n).attr('id')+jQuery(n).val();
        });
        
        if(code11.length > 0){
            var strs = code11.split(";"); 
            for(var i = 0; i < strs.length; i++) {
                var strs2 = strs[i].split(","); 
                for(var j = 0; j < strs2.length; j++) {
                    if(j%2==0){
                        code22 += strs2[j]+':'+strs2[j]+',';
                        code44 += 'var '+strs2[j] + '= $(\'#'+strs2[j] +'\').val();'

                    }
                }

            } 
            code22 += code22+'dede_addonfields:code11';
            code55 = code11 != null?",":"";
        }else{
            code22 = '';
            code55 = '';
        }
        
        eval(code44);
        code33 = '$.get("batch_action.php",{action :\'upload\',path:path,format:format,name:n,rank:i,typeid:typeid,ishtml:ishtml,articleName:articleName,copyInContent:copyInContent'+code55+code22+'}, function(data2){htmlCode += \'<li>\'+data2+\'</li>\'; $("#show").html(htmlCode); getcountDown(b,count);});';

        if(format == null || path == null || typeid == 0){
            alert('地址和格式不能为空');
        }else{
//            alert(code33);
            $.ajax({
                type: 'GET',
                url: 'batch_action.php',
                data: {action:'achieve',path:path,format:format,typeid:typeid},
                success:  function(data){
                    var jsonData=eval(data);
                    $.each(jsonData,  function(i, n){
                        var b = Number(i) +1;
                       
                        eval(code33);
                    });
                },
                dataType: 'json'
            });
        }
            $("#show").html(htmlCode);
        }
                     function getcountDown(n1,n2){
                     //alert(n1+'|'+n2);
                     $("#countDown").html('已经完成'+Math.round(n1/n2*100)+'%');
                     }         
        
    });

</script>
</head>
<body>
 <table _dlist="line check" class="tlist" align="center">
  <form name="form1" action="batch_action.php" method="get">
      <input type="hidden" id="count" >
  <tbody>
      <tr> 
      <td width="108" valign="top" bgcolor="#FFFFFF">注意：</td>
      <td width="377" valign="top" bgcolor="#FFFFFF">版本V1.0 获取最新版本请到 <a href="http://www.witheasy.com/" target="_blank">witheasy</a> </td>
      </tr>
      
    <tr> 
      <td width="108" valign="top" bgcolor="#FFFFFF">选择栏目：</td>
      <td width="377" valign="top" bgcolor="#FFFFFF"> 
    <?php
       if(empty($cid)) $cid=0;
       $tl = new TypeLink($cid);
       $typeOptions = $tl->GetOptionArray($cid,$cuserLogin->getUserChannel(),0,1);
       echo "<select name='typeid' id='typeid' style='width:300px'>\r\n";
       if($cid=='0') echo "<option value='0' selected='1'>请选择栏目...</option>\r\n";
       echo $typeOptions;
       echo "</select>";
		?>
      </td>
    </tr>

    <tr>
      <td height="20" valign="top" bgcolor="#FFFFFF">图片存放目录：</td>
      <td height="20" valign="top" bgcolor="#FFFFFF"><input name="path" type="text" class="txt" id="path" value="/uploads/files/">
        如 "files/2011/" 路径后面要加上 / </td>
    </tr>
    <tr>
      <td width="90">发布选项：</td>
            <td>
                <select id="ishtml">
                    <option value="1" selected="1">生成HTML</option>
                    <option value="0">仅动态浏览</option>
                </select>
            </td>
    </tr>
        <tr>
     <td width="90">作　者：</td>
            <td>
            	<input name="writer" type="text" class="txt" id="writer" style="width:120px" value="www.gzapp.net"/>    </td>
    </tr>
    
    <tr>
     <td width="90">&nbsp;文章来源：</td>
            <td width="240">
            	<input name="source" type="text" class="txt" id="source" style="width:160px" value="www.gzapp.net" size="16"/></td>
    </tr>
    <tr>
     <td width="90">&nbsp;把图片加进内容：</td>
            <td width="240">
            	<select id="copyInContent">
                    <option value="0" selected="1">否</option>
                    <option value="1">是</option>
                </select></td>
    </tr>
    <tr>
     <td width="90">&nbsp;文章命名方式：</td>
            <td width="240">
            	<select id="articleName">
                    <option value="0" selected="1">以文件名命名</option>
                    <option value="1">以文件存放文件夹名命名</option>
                </select>如果以文件存放文件夹名命名，将会自动生成序号，避免同名。</td>
    </tr>
    <tr>
        <td width="90">&nbsp;产品资料：</td>
            <td width="240"><div id="product"></div></td>
    </tr>
        <tr>
      <td height="20" valign="top" bgcolor="#FFFFFF">注意：</td>
      <td height="20" valign="top" bgcolor="#FFFFFF">文件名为图片名， 可以为中文。文件会在同级目录生成一个files文件夹用来储存文件，并更改文件名。上传成功后请把不必要的文件清除。</td>
    </tr>
    <tr> 
      <td height="20" valign="top" bgcolor="#FFFFFF">是否更新子栏目：</td>
      <td height="20" valign="top" bgcolor="#FFFFFF">
	  <input name="upnext" type="radio" class="np" value="jpg" id="formatjpg"/>
     <label for="formatjpg">JPG文件</label>  
    <input type="radio" name="upnext" class="np" value="png" id="formatpng"/>
     <label for="formatpng">PNG文件</label>
     <input type="radio" name="upnext" class="np" value="gif" id="formatgif"/>
     <label for="formatgif">GIF文件</label>
<!--    <input type="radio" name="upnext" class="np" value="rar" id="formatrar"/>
     <label for="formatrar">RAR文件</label>
         <input type="radio" name="upnext" class="np" value="zip" id="formatzip"/>
     <label for="formatzip">ZIP文件</label>-->
    </td>
    </tr>
    <tr> 
      <td height="20" colspan="2" bgcolor="#FAFAF1" align="center">
      <button type="button" class="btn1" id="go">开始批量上传</button>  
      </td>
    </tr>
  </form>
  </tbody>
  <tfoot>
  <tr bgcolor="#FFFFFF"> 
    <td colspan="2" id="mtd">
    	<div id='mdv' style='width:100%;height:350px;'> 
            <div id="countDown"></div>
            <div id="show"></div>
      </div>
	  </td>
  </tr>
  </tfoot>
</table>

</body>
</html>